<template>
    <div>
        <el-breadcrumb separator-icon="ArrowRight" style="margin: 16px">
            <el-breadcrumb-item :to="{ path: '/ManageHome' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>知识库管理</el-breadcrumb-item>
            <el-breadcrumb-item>知识库列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card style="margin: 15px; min-height: calc(100vh - 111px)">
            <div>
                <!--    功能区-->
                <div style="margin: 10px 0">
                    <!--    搜索区-->
                    <div style="margin: 10px 0">
                        <span
                            style="margin-left: 40px; margin-right: 14px; font-size: 15px; font-weight: 700;">知识库名称</span>
                        <el-input v-model="search" size="small" clearable placeholder="知识库名称"
                            prefix-icon="el-icon-search" style="width: 15%;" />
                        <el-button class="mybutton " icon="el-icon-search" @click="load"
                            style="background-color: #143371; color: aliceblue;"
                            size="small">搜索</el-button>
                        <el-button class="mybutton " icon="el-icon-refresh-left" style="margin-left: 5px;" @click="reset" size="small">重置</el-button>
                        <div style="float: right">
                            <el-tooltip content="添加知识库" placement="top">
                                <el-button class="mybutton " style="background-color: #143371; color: aliceblue;" size="small"
                                    @click="add">+新增</el-button>
                            </el-tooltip>
                        </div>
                    </div>
                </div>
                <div class="card-list" style="display: flex;flex-wrap: wrap;">
                    <div v-for="(item, index) in tableData" :key="index" @click="toKnowDetail(item.id)"
                        style="width: 24%; margin-top: 15px;">
                        <el-card style="margin-left: 20px;">
                            <div style="display: flex;justify-content: space-between;">
                                <div style="display: flex; width: 80%;">
                                    <div style="background-color:rgb(219 234 254); width: 70px; height: 70px; border-radius: 5px;"
                                        class="img-container">
                                        <img src="@/assets/image/doc.png" alt="" width="40%" style="margin-top: 1px;">
                                    </div>
                                    <div style="margin-left: 10px; width: 50%;">
                                        <p style="font-weight: bold;">{{ item.name }}</p>
                                        <p style="font-size: 12px; margin-top: 5px; color: gray;overflow: hidden;   text-overflow: ellipsis ">{{ item.des }}</p>
                                    </div>
                                </div>
                                <div style="width: 15%;">
                                    <i @click="handleEdit(scope.$index, scope.row)" class="el-icon-edit"
                                        style="margin-right: 5px;"></i>
                                    <i @click="handleDelete(scope.$index, scope.row)" class="el-icon-delete"></i>
                                </div>
                            </div>
                            <div style="color: gray; font-size: 12px; margin-top: 10px;">
                                <i class="el-icon-folder">文档数:{{ item.docCount }}</i>
                                <i class="el-icon-full-screen" style="margin-left: 10px;">大小:{{ parseSizeToMb(item.totalSize) }} MB</i>
                                <i class="el-icon-search" style="margin-left: 10px;">索引:{{ item.indexName }}</i>
                            </div>
                        </el-card>

                    </div>
                </div>
                <!--分页-->
                <div style="margin: 10px 0">
                    <el-pagination :currentPage="currentPage" :page-size="pageSize" :page-sizes="[10, 20]"
                        :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange"
                        @current-change="handleCurrentChange">
                    </el-pagination>
                </div>

                <div v-loading="dialogloading">
                    <!--  弹窗-->
                    <el-dialog :visible.sync="dialogVisible" title="操作" width="50%" @close="cancel" top="30px">
                        <div v-if="isDetail == 0">
                            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                                <el-form-item label="知识库名称" prop="provider">
                                    <el-input v-model="form.name" style="width: 80%" placeholder="名称"></el-input>
                                </el-form-item>
                                <el-form-item label="知识库描述" prop="name">
                                    <el-input type="textarea" v-model="form.des" style="width: 80%" placeholder="描述"></el-input>
                                </el-form-item>
                                <el-form-item label="关联的索引名" prop="indexName">
                                    <el-input v-model="form.indexName" style="width: 80%" placeholder="只能填写英文小写字母！"></el-input>
                                </el-form-item>
                            </el-form>

                        </div>
                        <div v-else>
                            <el-form ref="form" :model="form" :rules="rules" label-width="120px">
                                <el-form-item label="知识库名称" prop="provider">
                                    <el-input v-model="form.name" style="width: 80%" placeholder="名称"></el-input>
                                </el-form-item>
                                <el-form-item label="知识库描述" prop="name">
                                    <el-input v-model="form.des" style="width: 80%" placeholder="描述"></el-input>
                                </el-form-item>
                                <el-form-item label="关联的索引名" prop="indexName">
                                    <el-input v-model="form.indexName" style="width: 80%" placeholder="只能填写英文小写字母！"></el-input>
                                </el-form-item>
                            </el-form>
                        </div>
                        <template #footer>
                            <span class="dialog-footer" v-if="isDetail == 0">
                                <el-button @click="cancel">取 消</el-button>
                                <el-button type="primary" @click="save">确 定</el-button>
                            </span>
                        </template>
                    </el-dialog>
                </div>
            </div>
        </el-card>
    </div>
</template>
<script>
import request from '@/utils/request'
import { Upload } from 'element-ui';
export default {
    name: "ModelManage",
    data() {
        return {
            color: '#000000',
            dialogloading: false,
            isDetail: 0,
            value: null,
            loading: true,
            editJudge: true,
            judge: false,
            dialogVisible: false,
            search: null,
            currentPage: 1,
            pageSize: 10,
            total: 0,
            mode: 'default',
            tableData: [
                {
                    id: "1232421badad",
                    name: "客服知识库",
                    docCount: 2,
                    totalSize: 12042,
                    des: "关于客服知识库灌输式达到啊啊的八点",
                    indexName:"kefu_index"
                },
                {
                    id: "1232421badad",
                    name: "客服知识库",
                    docCount: 2,
                    totalSize: 12042,
                    des: "关于客服知识库",
                      indexName:"kefu_index"
                },
                {
                    id: "1232421badad",
                    name: "客服知识库",
                    docCount: 2,
                    totalSize: 12042,
                    des: "关于客服知识库",
                      indexName:"kefu_index"
                },
                {
                    id: "1232421badad",
                    name: "客服知识库",
                    docCount: 2,
                    totalSize: 12042,
                    des: "关于客服知识库",
                      indexName:"kefu_index"
                },
                {
                    id: "1232421badad",
                    name: "客服知识库",
                    docCount: 2,
                    totalSize: 12042,
                    des: "关于客服知识库",
                      indexName:"kefu_index"
                }

            ],
            form: {
                id: "1232421badad",
                name: "客服知识库",
                docCount: 2,
                totalSize: 12042,
                des: "关于客服知识库"
            },
            rules: {
            },
            editDisplay: {
                display: "block",
            },
            display: {
                display: "none",
            },
        };
    },
    created() {
        this.load();
        this.loading = false;
        setTimeout(() => {
            //设置延迟执行
            this.loading = false;
        }, 1000);
    },
    methods: {
        parseSizeToMb(num){
            num = num/(1024*1024)   
            return parseFloat(num.toFixed(2))
        },
      
        async load() {

        },
        reset() {
            this.search = null
            this.value = null,
                this.currentPage = 1;
            this.searchJob = null
            this.pageSize = 10
            this.load()
        },
        detail(index, row) {
            this.isDetail = 1;
            this.dialogVisible = true;
            // 赋值数据
            this.$nextTick(() => {
                this.form = row
            });
        },
        handleDelete(index, row) {
            // 确认框确认是否要删除
            this.$confirm("确定要删除的信息吗?", "删除提示", {
                iconClass: "el-icon-question", //自定义图标样式
                confirmButtonText: "残忍删除", //确认按钮文字
                cancelButtonText: "取消删除", //取消按钮文字
                showClose: true, //是否显示右上角关闭按钮
                type: "warning", //提示类型  success/info/warning/error
            }).then(() => {  //选择确认按钮进入此方法

            }).catch(() => { //选择取消按钮进入此方法
                //取消操作

            });
        },
        handleEdit(index, row) {
            this.judge = true;
            this.isDetail = 0;
            this.dialogVisible = true;
            this.$nextTick(() => {
                this.form = row
            });
        },
        cancel() {
            this.form = {}
            this.dialogVisible = false
        },
        save() {
            this.$refs.form.validate(vaild => {
                if (vaild) {
                    console.log(1111)
                    if (this.judge) {

                    }
                    else {
                        const loading = this.$loading({
                            lock: true,
                            text: '添加中',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                        });

                    }
                }
            })
        },
        formatDate(chinaTime) {
            const year = chinaTime.getFullYear();
            const month = (chinaTime.getMonth() + 1).toString().padStart(2, '0');
            const day = chinaTime.getDate().toString().padStart(2, '0');
            const hours = chinaTime.getHours().toString().padStart(2, '0');
            const minutes = chinaTime.getMinutes().toString().padStart(2, '0');
            const seconds = chinaTime.getSeconds().toString().padStart(2, '0');
            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        },
        add() {
            this.dialogVisible = true;
            this.isDetail = 0;
            this.judge = false;
            this.form = {}
        },
        handleSizeChange(pageSize) {
            //改变每页个数
            this.pageSize = pageSize;
            this.load();
        },
        handleCurrentChange(pageNum) {
            //改变页码
            this.currentPage = pageNum;
            this.load();
        },
        toKnowDetail(id){
            this.$router.push({
                path:"/Document",
                query:{
                    id:id
                }
            })
        }
    }


}
</script>
<style scoped>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    /* 防止边框和内边距影响宽度 */
}
.el-form-item {
    margin: 1px !important;
    padding: 8px !important;
}
.el-button {
    margin: 5px !important;
    padding: 8px !important;
}

.img-container {
    display: flex;
    /* 使用 flex 布局 */
    justify-content: center;
    /* 水平居中 */
    align-items: center;
    /* 垂直居中 */


}

.demo-table-expand {
    font-size: 0;
}

.demo-table-expand label {
    width: 150px;
    color: #99a9bf;
}

.demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 90%;
    display: block;
}

.demo-table-expand .el-form-item p {
    height: 30px;
    padding: 0px 0px;
    margin-bottom: 10px;
    margin-top: 10px;
}

.el-upload-list__item {
    transition: none !important;
}
</style>